﻿using JT808Protocol.Abstracts;
using JT808Protocol.Models;
using JT808Protocol.Models.BodyParserStrategy.Authenticate;
using System.Linq;

namespace JT808Protocol.Handlers
{
    /// <summary>
    /// 设备注册消息处理
    /// </summary>
    public class DeviceRegistrationHandler : MsgHandlerBase
    {
        public override EnumMessageType[] handleTypes => new EnumMessageType[] { EnumMessageType.终端注册 };

        public override JT808Package[] Execute(JT808Package reqPkg)
        {
            if (!handleTypes.Contains(reqPkg.Header.MessageType)) return null;

            var bodyRegister = new DpDevRegisterResponse_0x8100
            {
                SerialNum = reqPkg.Header.SerialNumber,
                Result = EnumDevRegisterType.成功,
                //默认返回设备注册成功
                AuthenticationCode = reqPkg.Header.SimNumber
            };
            return new[] { new JT808Package((ushort)EnumMessageType.终端注册应答, reqPkg.Header.SimNumber, (ushort)(reqPkg.Header.SerialNumber + 1), bodyRegister, Version: reqPkg.Header.ProtocolVersion) };
        }
    }
}